﻿using System;
using System.Collections.Generic;
using System.DirectoryServices;

namespace VMDS.GUIClient.Helper
{
    public static class AD
    {
        public static List<string> GetComputers()
        {
            List<string> pcs=new List<string>();
           string strPath = "";

			DirectoryEntry entry = new DirectoryEntry();
			DirectorySearcher mySearcher = new DirectorySearcher(entry);

			TimeSpan waitTime;
 				waitTime = new TimeSpan(0, 0, 60); //hh--mm-ss
            var objecttype = "computer";
			string strCat = "(objectCategory=" + objecttype + ")"; //desired object category like user,computer
            mySearcher.Filter = strCat;

				foreach(SearchResult result in 	mySearcher.FindAll()) 
				{
					var strName = result.GetDirectoryEntry().Name;
					strName = strName.Remove(0, 3); //delete "CN="
					pcs.Add(strName);
				}
            var array = pcs.ToArray();
            Array.Sort(array);
            pcs.Clear();
            pcs.AddRange(array);
            return pcs;
        }

    }
}
